<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-9-19
 * Func   福彩3D
 */
defined('IN_YuLin') || exit('NO PERMIT!');

//	返回中奖金额	data为订单信息，plays为玩法

function PrizeCount_4($data,$plays)
{
	global $db;
	
	if(!$data || !$data['result'] || !$plays)
	{
		return 0;
	}
	
	//	玩法
	$result = explode(',',$data['result']);
	
	//	三码复式
	if($plays['playid'] == 21073)
	{
		$tmp = explode('|',$data['rednum']);
		$tmp[0] = explode(',',$tmp[0]);
		$tmp[1] = explode(',',$tmp[1]);
		$tmp[2] = explode(',',$tmp[2]);
		
		return in_array($result[0],$tmp[0]) && in_array($result[1],$tmp[1]) && in_array($result[2],$tmp[2]) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	三码单式
	if($plays['playid'] == 21072)
	{
		$tmp3 = 0;	//	中奖个数
		$tmp2 = $result[0].$result[1].$result[2];
		$tmp = explode('_',$data['rednum']);
		foreach($tmp as $t)
		{
			$t == $tmp2 && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	三码直选和值
	$hezhi = array_sum($result);
	if($plays['playid'] == 21074)
	{
		return in_array($hezhi,explode('|',$data['rednum'])) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	组选三	选择1|2|3，那么只有开奖三个数中由1和2组成、或者1和3组成、或者2和3组成的号才中奖
	if($plays['playid'] == 21075)
	{
		$tmp4 = array_count_values($result);
		if(count($tmp4) != 2)
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$result) && $tmp3++;
		}
		
		return ($tmp3 > 1) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	组选六
	if($plays['playid'] == 21077)
	{
		$tmp4 = array_count_values($result);	//	出现重复号就不可以中奖
		if(count($tmp4) != 3)
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$result) && $tmp3++;
		}
		
		return ($tmp3 > 2) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	混合组选
	if($plays['playid'] == 21079)
	{
		$tmp4 = array_count_values($result);	//	出现重复号就只能中组三
		if(count($tmp4) == 1)	//	豹子
		{
			return 0;
		}
		
		$tmp8 = 0;	//	所中奖金
		
		//	组三和组六奖金
		$t2 = $db->getall('SELECT maxprize FROM '.Table('lottery_play').' WHERE playid = '.$plays['playid'].' AND cid = '.$plays['cid'].' ORDER BY maxprize');
		
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t1)
		{
			$tmp3 = 0;
			
			$tmp2 = explode(',',$t1);
			foreach($tmp2 as $t4)
			{
				in_array($t4,$result) && $tmp3++;
			}
			
			if($tmp3 > 2)	//	组六
			{
				$tmp8 += $t2[0]['maxprize'];
			}
			else if($tmp3 > 1 && count($tmp4) == 2)	//	组三
			{
				$tmp8 += $t2[1]['maxprize'];
			}
		}
		
		return $tmp8 ? $tmp8 * $data['times'] : 0;
	}
	
	//	组选和值
	if($plays['playid'] == 21080)
	{
		$tmp4 = array_count_values($result);	//	出现重复号就只能中组三
		if(count($tmp4) == 1)	//	豹子
		{
			return 0;
		}
		
		$tmp = explode('|',$data['rednum']);
		if(!in_array($hezhi,$tmp))
		{
			return 0;
		}
		
		//	组三和组六奖金
		$t2 = $db->getall('SELECT maxprize FROM '.Table('lottery_play').' WHERE playid = '.$plays['playid'].' AND cid = '.$plays['cid'].' ORDER BY maxprize');
		
		if(count($tmp4) == 3)	//	组六
		{
			$tmp8 = $t2[0]['maxprize'];
		}
		else	//	组三
		{
			$tmp8 = $t2[1]['maxprize'];
		}
		
		return $tmp8 * $data['times'];
	}
	
	//	一码不定胆
	if($plays['playid'] == 21083)
	{
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$result) && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	二码不定胆
	if($plays['playid'] == 21084)
	{
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$result) && $tmp3++;
		}
		
		return $tmp3 > 1 ? NumGroup($tmp3,2) * $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	前二复式
	if($plays['playid'] == 21085)
	{
		$tmp = explode('|',$data['rednum']);
		$tmp[0] = explode(',',$tmp[0]);
		$tmp[1] = explode(',',$tmp[1]);
		
		return in_array($result[0],$tmp[0]) && in_array($result[1],$tmp[1]) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	前二单式
	if($plays['playid'] == 21086)
	{
		$tmp3 = 0;	//	中奖个数
		$tmp2 = $result[0].$result[1];
		$tmp = explode('_',$data['rednum']);
		foreach($tmp as $t)
		{
			$t == $tmp2 && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	前二组选复式
	if($plays['playid'] == 21087)
	{
		//	出现重复号就不可以中奖
		if($result[0] == $result[1])
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp2 = [$result[0],$result[1]];
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$tmp2) && $tmp3++;
		}
		
		return ($tmp3 > 1) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	前二组选单式
	if($plays['playid'] == 21088)
	{
		//	出现重复号就不可以中奖
		if($result[0] == $result[1])
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			$t = explode(',',$t);
			(($t[0] == $result[0] && $t[1] == $result[1]) | ($t[0] == $result[1] && $t[1] == $result[0])) && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	后二复式
	if($plays['playid'] == 21089)
	{
		$tmp = explode('|',$data['rednum']);
		$tmp[0] = explode(',',$tmp[0]);
		$tmp[1] = explode(',',$tmp[1]);
		
		return in_array($result[1],$tmp[0]) && in_array($result[2],$tmp[1]) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	后二单式
	if($plays['playid'] == 21090)
	{
		$tmp3 = 0;	//	中奖个数
		$tmp2 = $result[1].$result[2];
		$tmp = explode('_',$data['rednum']);
		foreach($tmp as $t)
		{
			$t == $tmp2 && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	后二组选复式
	if($plays['playid'] == 21091)
	{
		//	出现重复号就不可以中奖
		if($result[1] == $result[2])
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp2 = [$result[1],$result[2]];
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			in_array($t,$tmp2) && $tmp3++;
		}
		
		return ($tmp3 > 1) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	后二组选单式
	if($plays['playid'] == 21092)
	{
		//	出现重复号就不可以中奖
		if($result[1] == $result[2])
		{
			return 0;
		}
		
		$tmp3 = 0;
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $t)
		{
			$t = explode(',',$t);
			(($t[0] == $result[1] && $t[1] == $result[2]) | ($t[0] == $result[2] && $t[1] == $result[1])) && $tmp3++;
		}
		
		return $tmp3 * $plays['maxprize'] * $data['times'];
	}
	
	//	定位胆百位
	if($plays['playid'] == 21093)
	{
		$tmp = explode('|',$data['rednum']);
		
		return in_array($result[0],$tmp) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	定位胆十位
	if($plays['playid'] == 21332)
	{
		$tmp = explode('|',$data['rednum']);
		
		return in_array($result[1],$tmp) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	定位胆个位
	if($plays['playid'] == 21333)
	{
		$tmp = explode('|',$data['rednum']);
		
		return in_array($result[2],$tmp) ? $plays['maxprize'] * $data['times'] : 0;
	}
	
	//	前二大小单双
	if($plays['playid'] == 21094)
	{
		$da = [$result[0] > 4,$result[1] > 4];
		$dan = [$result[0] % 2,$result[1] % 2];
		
		$tmp3 = [0,0];
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $k2 => $t2)
		{
			$t2 = explode(',',$t2);
			if($da[$k2])
			{
				in_array('大',$t2) && $tmp3[$k2]++;
			}
			else
			{
				in_array('小',$t2) && $tmp3[$k2]++;
			}
			
			if($dan[$k2])
			{
				in_array('单',$t2) && $tmp3[$k2]++;
			}
			else
			{
				in_array('双',$t2) && $tmp3[$k2]++;
			}
		}
		
		return $tmp3[0] * $tmp3[1] * $plays['maxprize'] * $data['times'];
	}
	
	//	后二大小单双
	if($plays['playid'] == 21095)
	{
		$da = [$result[1] > 4,$result[2] > 4];
		$dan = [$result[1] % 2,$result[2] % 2];
		
		$tmp3 = [0,0];
		$tmp = explode('|',$data['rednum']);
		foreach($tmp as $k2 => $t2)
		{
			$t2 = explode(',',$t2);
			if($da[$k2])
			{
				in_array('大',$t2) && $tmp3[$k2]++;
			}
			else
			{
				in_array('小',$t2) && $tmp3[$k2]++;
			}
			
			if($dan[$k2])
			{
				in_array('单',$t2) && $tmp3[$k2]++;
			}
			else
			{
				in_array('双',$t2) && $tmp3[$k2]++;
			}
		}
		
		return $tmp3[0] * $tmp3[1] * $plays['maxprize'] * $data['times'];
	}
	
	return 0;
}